import './assets/main.css'

import { createApp } from 'vue'
import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import App from './App.vue'
import router from './router'
import './utils/piniaTokenTest'

const app = createApp(App)
const pinia = createPinia()

// 配置Pinia持久化插件
pinia.use(createPersistedState({
  auto: true,  // 自动持久化所有store
  storage: localStorage,  // 使用localStorage
}))

app.use(ElementPlus)
app.use(pinia)
app.use(router)

// 在应用启动后检查token有效性
app.mount('#app')

// 等待Pinia状态恢复完成后检查token
setTimeout(() => {
  const { useUserStore } = require('./stores/user')
  const userStore = useUserStore()
  userStore.checkTokenValidity()
}, 0)
